﻿using cpe.cpein.SERVER.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace cpe.cpein.SERVER.Tools
{
    public static partial class ObjectConverter
    {
        /// <summary>
        /// Function used to convert a WS Country to a Data Country.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static DATA.Country CountryConverter(Country Country)
        {
            if (Country == null)
                return null;

            return new DATA.Country()
            {
                cou_id = Country.Id,
                cou_label = Country.Label,
                are_id = Country.IDArea,
                cou_isdeleted = Country.IsDeleted,
            };
        }

        /// <summary>
        /// Function used to convert a Data Country to a WS Country.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static Country CountryConverter(DATA.Country Country)
        {
            if (Country == null)
                return null;

            Area area = Tools.ObjectConverter.AreaConverter(BUSINESS.BUArea.GetAreaByID(Country.are_id));

            return new Country()
            {
                Id = Country.cou_id,
                Label = Country.cou_label,
                IDArea = Country.are_id,
                Area = area,
                IsDeleted = Country.cou_isdeleted,
            };
        }

        /// <summary>
        /// Function used to convert a list of Data Countrys to a List of WS Countrys.
        /// </summary>
        /// <param name="Countrys"></param>
        /// <returns></returns>
        public static List<Country> CountryConverter(List<DATA.Country> Countrys)
        {
            List<Country> res = new List<Country>();
            foreach (DATA.Country us in Countrys)
                res.Add(Tools.ObjectConverter.CountryConverter(us));

            return res;
        }

        /// <summary>
        /// Function used to convert a list of WS Countrys to a List of Data Countrys.
        /// </summary>
        /// <param name="Countrys"></param>
        /// <returns></returns>
        public static List<DATA.Country> CountryConverter(List<Country> Countrys)
        {
            List<DATA.Country> res = new List<DATA.Country>();
            foreach (Country us in Countrys)
                res.Add(Tools.ObjectConverter.CountryConverter(us));

            return res;
        }
    }
}